<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
   <script>
       /* 
       ^  以什么开头,
       $  以什么结尾
       trim();   --去除前后的空格  reg=/^\s+|\s$/g
       */
       var str="   hello world";
       var s="hello   ";
       var t="   hello world    "
       var reg=/^\s+/;    //以空格开头就将它用*替换掉
       console.log(str.replace(reg,"*"))   //*hello world
       var r=/\s+$/;
       console.log(s.replace(r,"*"))     //hello*
       console.log(t.replace(/^\s+|\s$/g,"*"))   //*hello world   *
    </script> 
</body>
</html>